﻿using System;
using System.Collections.Generic;
//using System.Linq;
using System.Text;
using System.Collections;
using System.IO;
using Tools.Data;
using System.Data;
using System.Data.SQLite;
using System.Xml;
using System.Threading.Tasks;
using ConsoleApplication7.Model;
namespace ConsoleApplication7
{
    public interface Observer
    {
        void Response();         //观察者的响应，如是老鼠见到猫的反映   
    }
    public interface Subject
    {
        void AimAt(Observer obs);     //针对哪些观察者，这里指猫的要扑捉的对象---老鼠   
    }
    public class Mouse : Observer
    {
        private string name;
        public Mouse(string name, Subject subj)
        {
            this.name = name;
            subj.AimAt(this);
        }

        public void Response()
        {
            Console.WriteLine(name + "   attempt   to   escape!");
        }
    }
    public class Master : Observer
    {
        public Master(Subject subj)
        {
            subj.AimAt(this);
        }

        public void Response()
        {
            Console.WriteLine("Host   waken!");
        }
    }

    public class Cat : Subject
    {
        private ArrayList observers;
        public Cat()
        {
            this.observers = new ArrayList();
        }
        public void AimAt(Observer obs)
        {
            this.observers.Add(obs);
        }
        public void Cry()
        {
            Console.WriteLine("Cat   cryed!");
            foreach (Observer obs in this.observers)
            {
                obs.Response();
            }
        }
    } 
    class Program
    {
        //static void Main(string[] args)
        //{
        //    string pat = @"C:\Users\jdd01\AppData\Roaming\Mozilla\Firefox\Profiles\752aure0.default";
        // string []dor=   System.IO.Directory.GetFiles(pat, "*.sqlite", SearchOption.TopDirectoryOnly);
        //    System.Text.StringBuilder strub = new StringBuilder();
        //    foreach (string item in dor)
        //    {
        //        strub.AppendFormat("<item name=\"{0}\">{1}</item>",Path.GetFileName(item),item);
        //    }
        //    Clog.Write("1", strub.ToString());
        //    Console.WriteLine("Cat   cryed!"+Path.DirectorySeparatorChar.ToString());
        //}
        static void Main(string[] args)
        {
        	CC1.log();
        	
			//TSavle.Save();
           //string cosoleparam= Console.ReadLine();
          // if (cosoleparam=="history-all")
          // {
			   //#region all mozlilla history
			   //foreach (KeyValuePair<string,string> item in HistoryConfig.GetHistory())
			   //{
                   
			   //}
			   //#endregion
         //  }


        }
        static DataTable Readfile(string path,string pre) {
            DataSet ds = Read_DataSet(path, "select tbl_name,sql from sqlite_master  where type='table'");
            DataTable dt = new DataTable();
           if (ds!=null)
           {
               if (ds.Tables.Count>0)
               {
                   if (ds.Tables[0]!=null &&ds.Tables[0].Rows.Count>0)
                   {
                        dt = ds.Tables[0];
                       
                   }
               }
           }
           return dt;
        }
        /// <summary>
        /// 表名，列名
        /// </summary>
        /// <param name="sql"></param>
        /// <returns></returns>
        static List<Sqlite_TableName> HandSqliteSql(string sql) {
            return HandSqliteSql(sql, "");
        }
        static List<Sqlite_TableName> HandSqliteSql(string sql,string pre)
        {
            List<Sqlite_TableName> list = new List<Sqlite_TableName>();
            if (sql == "")
            {
                return null;

            }

            if (sql.Contains("("))
            {
                string[] sp = sql.Split(new string[] { "(" }, StringSplitOptions.RemoveEmptyEntries);
                Sqlite_TableName c1 = new Sqlite_TableName();
                c1.tableName = sp[0].Replace("CREATE TABLE ", "");
                string[] sp1 = sp[1].Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                foreach (string item in sp1)
                {
                    string[] sp2 = item.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
                    c1.List_col.Add(new Sqlite_column() { columnName = sp2[0], Col_Sqlit_type = sp2[1] });
                }
                if (pre!="")
                {
                      c1.List_col.Add(new Sqlite_column() { columnName = pre, Col_Sqlit_type = "text" });
                }
              
                list.Add(c1);
            }
            return list;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="item"></param>
        /// <param name="sql"></param>
        /// <returns></returns>
        static DataSet Read_DataSet(string item,string sql)
        {
            DataSet ds = new DataSet();
            try
            {
SQLiteConnectionStringBuilder builder = new SQLiteConnectionStringBuilder();
            builder.DataSource = item;
          
            builder.PageSize = 4096;
            builder.UseUTF16Encoding = true;
            string connstring = builder.ConnectionString;
            ds = SQLiteHelper.ExecuteDataSet(connstring, new System.Data.SQLite.SQLiteCommand(sql));//"select * from sqlite_master"
               
            }
            catch (Exception ee)
            {
                Clog.Write(Path.GetFileName(item),item+ ee.Message);
            }
            return ds;
        }
    }
   
}
